package com.alfayun.fiscalriskanalysis.another.indicator;

import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

import com.alfayun.fiscalriskanalysis.another.report.Report;
import com.alfayun.fiscalriskanalysis.another.specification.indicator.IndicatorSpec;

public final class Indicator {

	private IndicatorSpec spec;

	private Set<Selector> selectors;
	private Set<Measure> measures;
	private Set<Alert> alerts;

	public Indicator(IndicatorSpec spec, Collection<Report> reports) {
		this.spec = spec;

		bindSelector(reports);
		calcMeasure();
		triggerAlert();
	}

	private void bindSelector(Collection<Report> reports) {
		selectors = spec.getAllSelectors().stream().map(e -> Selectors.bind(e, reports)).collect(Collectors.toSet());
	}

	private void calcMeasure() {
		measures = spec.getAllMeasures().stream().map(e -> Measures.create(e, selectors)).collect(Collectors.toSet());
	}

	private void triggerAlert() {
		alerts = spec.getAllAlerts().stream().map(e -> Alerts.create(e, measures)).collect(Collectors.toSet());
	}

}
